import sys
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import QDir
from qt_material import export_theme


def init_theme(qss_name: str, app: QApplication):
    """初始化主题"""
    # Load stylesheet
    with open(qss_name, 'r') as file:
        app.setStyleSheet(file.read())

    # Register icon prefix
    QDir.addSearchPath('icon', 'theme')


def export_theme_to_file():
    """导出主题"""

    extra = {
        # Button colors
        'danger': '#dc3545',
        'warning': '#ffc107',
        'success': '#17a2b8',

        # Font
        'font_family': 'SimHei',
        'font_size': '12px',
        'line_height': '12px',

        # Density Scale
        'density_scale': '-1',

        # Environment hints
        'pyside6': True,
        'linux': True,
    }

    export_theme(theme='dark_teal.xml',
                 qss='dark_teal.qss',
                 rcc='resources.rcc',
                 output='theme',
                 prefix='icon:/',
                 invert_secondary=False,
                 extra=extra,
                 )
